class UsersController < ApplicationController
  
  def index
    if current_user
      @users = User.all
      respond_to do |format|
        format.html
        format.json { render json: @users }
      end
    else
      redirect_to('/')
    end
  end
  
  def show
    if current_user
      @user = User.find(params[:id])
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @user }
      end
    else
      redirect_to('/')
    end
  end
  def edit
    @user = User.find(params[:id])
  end
  
  def update
    if current_user
      @user = User.find(params[:id])
      respond_to do |format|
        if @user.update_attributes(params[:user])
          format.html { redirect_to @user, notice: 'User was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @user.errors, status: :unprocessable_entity }
        end
      end
    else
      redirect_to('/')
    end
  end
end
